package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"net"
	"os"
	"strings"
)

func main() {
	servers := os.Args[1:]
	ch := make(chan map[string]string)
	for _, server := range servers {
		ser := strings.Split(server, "=")
		go func(add string) {
			conn, err := net.Dial("tcp", ser[1])
			if err != nil {
				log.Fatal(err)
			}
			defer conn.Close()
			mustCopy(ch, conn, add)
		}(ser[0])

	}
	for m := range ch {
		for k, v := range m {
			fmt.Printf("%s: %s\n", k, v)
		}
	}
}

func mustCopy(ch chan map[string]string, src io.Reader, add string) {
	scanner := bufio.NewScanner(src)
	for scanner.Scan() {
		ch <- map[string]string{add: scanner.Text()}
	}
}
